using System;
using UnityEngine;

namespace BitMango
{
	[Serializable]
	public class ShopItem
	{
		public bool IsCashPrice()
		{
			return this.type == ItemType.Cash2Item;
		}

		public bool IsActionPrice()
		{
			return this.type == ItemType.Action2Item;
		}

		public PriceType GetPriceType()
		{
			if (this.IsCashPrice())
			{
				return PriceType.Cash;
			}
			return PriceType.Action;
		}

		public bool IsTangibleItem()
		{
			return this.type == ItemType.Cash2Item;
		}

		public string GetPrice()
		{
			return this.price;
		}

		public string GetServerPrice()
		{
			if (string.IsNullOrEmpty(this.serverPrice))
			{
				return this.price;
			}
			return this.serverPrice;
		}

		public void SetServerPrice(string sPrice)
		{
			this.serverPrice = sPrice;
		}

		public string GetPriceID()
		{
			return this.productId;
		}

		public string GetBuyButtonName()
		{
			if (!this.IsActionPrice())
			{
				return "buy";
			}
			string[] array = this.GetPriceID().Split(new char[]
			{
				'@'
			});
			if (array.Length != 2)
			{
				UnityEngine.Debug.LogError("Action ShopItem \"" + this.id + "\" PriceID is mal formrmed \n Valid Format : [ButtonName]@[GameObjectName].[MessageToSend]");
				return string.Empty;
			}
			return array[0];
		}

		public string GetActionTarget()
		{
			if (!this.IsActionPrice())
			{
				return "buy";
			}
			string[] array = this.GetPriceID().Split(new char[]
			{
				'@'
			});
			string[] array2 = array[1].Split(new char[]
			{
				'.'
			});
			if (array.Length != 2 || array2.Length != 2)
			{
				UnityEngine.Debug.LogError("Action ShopItem \"" + this.id + "\" PriceID is mal formrmed \n Valid Format : [ButtonName]@[GameObjectName].[MessageToSend]");
				return string.Empty;
			}
			return array2[0];
		}

		public string GetActionMethod()
		{
			if (!this.IsActionPrice())
			{
				return "buy";
			}
			string[] array = this.GetPriceID().Split(new char[]
			{
				'.'
			});
			if (array.Length != 2)
			{
				UnityEngine.Debug.LogError("Action ShopItem \"" + this.id + "\" PriceID is mal formrmed \n Valid Format : [ButtonName]@[GameObjectName].[MessageToSend]");
				return string.Empty;
			}
			return array[1];
		}

		public bool IsInfinite
		{
			get
			{
				if (this.rewards.Length == 0)
				{
					UnityEngine.Debug.LogError("ShopItem \"" + this.id + "\" rewards is not set");
					return false;
				}
				return this.rewards[0].count == int.MaxValue || this.rewards[0].count < 0;
			}
		}

		public bool IsSellable
		{
			get
			{
				if (!this.enabled)
				{
					return this.enabled;
				}
				InventoryItem inventoryItem = Wallet.Get(this.rewards[0].itemId);
				if (inventoryItem == null)
				{
					return this.enabled;
				}
				return !inventoryItem.IsInfinite && (inventoryItem.consumable || inventoryItem.count <= 0);
			}
		}

		public string id;

		public ItemType type;

		public Texture2D icon;

		public bool consumable;

		public string name;

		public string description;

		public bool enabled = true;

		public ShopItem.Package[] rewards;

		public string price;

		public string serverPrice;

		public string productId;

		public enum Category
		{
			Item,
			Reward
		}

		[Serializable]
		public class Package
		{
			public InventoryItem GetItem()
			{
				return Wallet.Get(this.itemId);
			}

			public bool IsInfinite
			{
				get
				{
					return this.count == int.MaxValue || this.count < 0;
				}
			}

			public string itemId;

			public int count;
		}
	}
}
